<template>
    <div class="sidebar">
        <el-menu
            class="sidebar-el-menu"
            :default-active="onRoutes"
            :collapse="collapse"
            background-color="#214A8F"
            text-color="#bfcbd9"
            active-text-color="#20a0ff"
            unique-opened
            router
        >
            <template v-for="item in items">
                <template v-if="item.subs">
                    <el-submenu :index="item.index" :key="item.index">
                        <template slot="title">
                            <!-- <i :class="item.icon"></i> -->
                            <img style="width:22px;margin-right:20px" :src="item.img" alt="">
                            <span slot="title">{{ item.title }}</span>
                        </template>
                        <template v-for="subItem in item.subs">
                            <el-submenu v-if="subItem.subs" :index="subItem.index" :key="subItem.index">
                                <template slot="title">{{ subItem.title }}</template>
                                <el-menu-item v-for="(threeItem, i) in subItem.subs" :key="i" :index="threeItem.index">{{
                                    threeItem.title
                                }}</el-menu-item>
                            </el-submenu>
                            <el-menu-item v-else :index="subItem.index" :key="subItem.index" class="upItem">{{
                                subItem.title
                            }}</el-menu-item>
                        </template>
                    </el-submenu>
                </template>
                <template v-else>
                    <el-menu-item :index="item.index" :key="item.index">
                        <i :class="item.icon"></i>
                        <span slot="title">{{ item.title }}</span>
                    </el-menu-item>
                </template>
            </template>
        </el-menu>
        <div class="sidebarImg">
            <img src="../../assets/img/siberbg.png" />
        </div>
    </div>
</template>

<script>
import bus from '../common/bus';
export default {
    data() {
        return {
            collapse: false,
            items: []
        };
    },
    computed: {
        onRoutes() {
            return this.$route.path.replace('/', '');
        }
    },
    methods: {
        //动态获取菜单列表
        getTypes() {
            if (localStorage.getItem('type') == 0 || 1) {
                this.items = [
                    {
                        
                        img:require('../../assets/img/shuju.png'),
                        index: '8',
                        title: '项目部管理',
                        subs: [
                            {
                                index: 'newObjectList',
                                title: '新项目'
                            },
                            {
                                index: 'doingObject',
                                title: '进行中项目'
                            },
                            {
                                index: 'history',
                                title: '历史项目'
                            }
                        ]
                    },
                    // {    
                    //      img:require('../../assets/img/renqun.png'),
                        
                    //     index: '9',
                    //     title: '事业部管理',
                    //     subs: [
                    //         {
                    //             index: 'newDepartment',
                    //             title: '账号管理'
                    //         }
                    //     ]
                    // }
                ];
            }
            if (localStorage.getItem('type') == 2) {
                this.items = [
                    {
                        // icon: 'el-icon-data-line',
                        img:require('../../assets/img/shuju.png'),
                        index: '8',
                        title: '项目部管理',
                        subs: [
                            {
                                index: 'doingObject',
                                title: '进行中项目'
                            },
                            {
                                index: 'history',
                                title: '历史项目'
                            }
                        ]
                    }
                ];
            }
            if (localStorage.getItem('type') == 3) {
                this.items = [
                    {
                        // icon: 'el-icon-data-line',
                        img:require('../../assets/img/shuju.png'),
                        index: '8',
                        title: '项目部管理',
                        subs: [
                            {
                                index: 'doingObject',
                                title: '进行中项目'
                            }
                        ]
                    }
                ];
            }
            if (localStorage.getItem('type') == 4) {
                this.items = [
                    {
                        
                        img:require('../../assets/img/shuju.png'),
                        index: '8',
                        title: '项目部管理',
                        subs: [
                            {
                                index: 'newObjectList',
                                title: '新项目'
                            },
                            {
                                index: 'doingObject',
                                title: '进行中项目'
                            },
                            {
                                index: 'history',
                                title: '历史项目'
                            }
                        ]
                    }
                ];
            }
        }
    },
    mounted() {
        this.getTypes();
    },
    created() {
        // 通过 Event Bus 进行组件间通信，来折叠侧边栏
        // bus.$on('collapse', msg => {
        //     this.collapse = msg;
        //     bus.$emit('collapse-content', msg);
        // });
    }
};
</script>

<style lang="scss" scoped>
.sidebar {
    display: block;
    position: absolute;
    left: 0;
    top: 80px;
    bottom: 0;
    box-sizing: border-box;
    // background-color: rgb(33, 74, 143);
}
.sidebar::-webkit-scrollbar {
    width: 0;
}
.sidebar-el-menu:not(.el-menu--collapse) {
    width: 240px;
    overflow: hidden;
}
.sidebar > ul {
    padding-top: 120px;
    // background: rgba(255, 255, 255, 0.1) !important;
    // border-radius:20px ;
    // padding-bottom:40px;
    height: 100%;
}
// .sidebar /deep/.el-menu{
//     display:flex;
//     justify-content: center;
// }
.sidebar .subClass {
    width: 150px;
    padding-top: 20px;
    padding-bottom: 20px;
}
.sidebar /deep/.el-menu-item {
    min-width: 60px;
    width: 150px;
    height: 35px;
    line-height: 35px;
    // margin-left: 40px;

    padding-left: 32px !important;
    background: rgba(255, 255, 255, 0) !important;

    color: #000;
    position: relative;
    // text-align: center;
}
.sidebar /deep/.el-menu--inline {
    width: 150px;
    margin-left: 40px;
    border-radius: 10px;
    // padding-top:24px;
    // padding-bottom:24px;
    background: rgba(255, 255, 255, 0.1) !important;
}
.sidebar /deep/.el-menu-item {
    margin-top: 24px;
    margin-bottom: 24px;
}

.sidebar /deep/.el-menu-item.is-active {
    color: #214a8f !important;
    background: #fff !important;
    // color: #000;
}
.sidebar /deep/.is-active:before {
    // width:100px;
    // height:100px;
    // border-left:35px solid red;
    //  position: absolute;
    //  left:0px;
    //  top:0px;
    // background:red;
    // z-index:999;
    content: '';
    position: absolute;
    right: -16px;
    top: 10px;
    border: 8px solid transparent;
    // transition: opacity 2s;

    border-left-color: #fff;
    animation: arrowShow 1s;
}
.sidebar /deep/.el-submenu__title {
    padding-left: 40px !important;
    padding-right: 26px !important;
}
.sidebar /deep/.is-opened {
    margin-bottom: 80px;
}
.sidebar /deep/.el-submenu__title i {
    color: #fff;
}
.sidebar /deep/.el-submenu__title {
    color: #fff !important;
    font-size: 16px;
    // width:80px;
    // height:21px;
    // line-height:21px;
}
.sidebar /deep/.el-menu-item {
    color: #fff !important;
}
@keyframes arrowShow {
    0% {
        opacity: 0;
    }
    100% {
        opacity: 1;
    }
}
//修改背景图片
.sidebarImg {
    position: absolute;
    bottom: -4px;
    // z-index: 1;
    width: 242px;
    // height: 202px;
}
</style>
